import {
  HTTP
} from "../utils/http.js"
const tips = {
  9000: '订单支付成功',
  8000: '正在处理中',
  4000: '订单支付失败',
  6001: '用户中途取消',
  6002: '网络连接出错',
  6004: '支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态',
  99: '用户点击忘记密码导致快捷界面退出', //(only iOS)
}
class PayModel extends HTTP {
  createTrade(amount, realAmount, subject, shopId, goodsId, oilGunId, id, couponId, jiayouSource) {
    return this.request({
      url: 'program/antProgramApiService/payment',
      data: {
        amount,
        realAmount,
        subject,
        shopId,
        goodsId,
        oilGunId,
        id,
        couponId,
        jiayouSource
      },
      method: 'POST'
    })
  }
  createTradeNew(payPassword,payType,amount, realAmount, subject, shopId, jiayouSource,orderId,oilGunNo,deliveryId) {
    return this.request({
      url: 'bj/bjShellAntMiniProgramService/paymentRequest',
      data: {
        payPassword,
        payType,
        amount,
        realAmount,
        subject,
        shopId,
        jiayouSource,
        orderId,
        oilGunNo,
        deliveryId
      },
      method: 'POST'
    })
  }
  recharge(amount, realAmount, mobilePhone, shopId) {
    return this.request({
      url: 'program/antProgramApiService/recharge',
      data: {
        amount,
        realAmount,
        mobilePhone,
        shopId,
      },
      method: 'POST'
    })
  }  
  myPay(tip,NO, amount,href,orderID) {
    my.tradePay({
      tradeNO: NO,
      success: function (res) {
        console.log(res)
        if (res.resultCode == 9000) {
          console.log('支付成功了-----------------' + JSON.stringify(res))
          my.showToast({
              type: 'success',
              content: '支付成功',
              duration: 1000,
          })
          setTimeout(() => {
            if (tip == 'recharge') {
              if (href) {
                if (href == 'oilConfirm' || href == 'oilResult' ) {
                  my.redirectTo({
                    url: '/pages/recharge/rechargeResult/rechargeResult?amount=' + amount +'&orderId=' + NO + '&href=' + href + '&yhorderID=' + orderID
                  })
                  return
                }
              }
              my.redirectTo({
                url: '/pages/recharge/rechargeResult/rechargeResult?amount=' + amount +'&orderId=' + NO + '&yhorderID=' + orderID
              })
            } else {
              my.redirectTo({
                url: '/pages/oil/oilResult/oilResult?tradeNo=' + NO + '&yhorderID=' + orderID
              })
            }
          }, 1000)
        } else if (res.resultCode == 6001) {

        } else {
          my.alert({
            content: tips[res.resultCode]
          });
        }
      },
      fail: function (res) {
        console.log(res)
        my.alert({
          content: JSON.stringify(res),
        });
      },
    });
  }
}
export {
  PayModel
}